<template>
  <div>
  <p>
  <br>
  <br>
  <br>
  <button @click="wechat()">test</button>
  <p>
payload
{{this.wepayload}}
  </p>
  <p>
  Lepay
{{this.Lepay}}
  </p>
  </div>
</template>
</html>
<script type="text/javascript">

export default {
  data() {
    return {
       wepayload:{
         actionName: "LePay",
         url:'lepay',
         postData: {
      			"orderId":'',
            "name":"knowledge",
            "catCode":"1",
            "device":"3",
            "payType":"3",
            "amount":"",
            "openid": ""
      	   // "appId":Appid, //   "timeStamp":Timestamp, //   "nonceStr":Noncestr, //   "package":Pkg, //   "signType":"MD5", //   "paySign":Sign }
       }
      }
    }
  },
  created(){
    // https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf915dbfb1b2c6ab8&redirect_uri=http%3A%2F%2Fwx.lep365.com%2FWeChat%2Fst%2FsnsapiBase&response_type=code&scope=snsapi_base&state=kcgm&connect_redirect=1#wechat_redirect
    if (this.$route.params.openId != 1234) {
      this.wepayload.postData.orderId = window.localStorage.getItem('setorderid')
      this.wepayload.postData.amount = window.localStorage.getItem('setmount')
      // this.wepayload.postData.openid = this.$route.params.openId ;
      this.wepayload.postData.openid = this.$route.params.openId ;
      // this.wepayload.postData.amount= this.$route.params.totalprice;
       this.$store.commit('restful_api',this.wepayload)
    }else {
      console.info(5678); alert(56789)
      window.localStorage.setItem('setorderid',this.$route.params.orderId)
      window.localStorage.setItem('setmount',this.$route.params.totalprice)
     //  this.$store.commit('restful_api',this.wepayload) // this.$wechat.ready({ "appId":Appid, "timeStamp":Timestamp, "nonceStr":Noncestr, "package":Pkg, "signType":"MD5", "paySign":Sign })
      this.wepayload.postData.orderId= this.$route.params.orderId
      // this.wepayload.postData.openid = "oreW2w8nlZnBAGjcNjEAZmihep00"
      this.wepayload.postData.amount= this.$route.params.totalprice
    }

    var x = this.$route.params.orderId ;
    // this.wepayload.postData.openid = this.$route.params.openId
if (this.wepayload.postData.openid =='') {
  alert('stop id')
  setTimeout(function () {
    window.location.href='http://m.lep365.com/get-weixin-code.html?appid=wxf915dbfb1b2c6ab8&scope=snsapi_base&state=kcgm'
  }, 500);

} else {

    this.wepayload.postData.openid = this.$route.params.openId
    setTimeout(function () {
        alert('did go ?')
        this.wechat()
        alert(this.wepayload.postData.openid)
    }.bind(this),1000 );
}
      // this.wepayload.orderId = this.$route.params.orderId
  },
  computed :{
    url() {
      return  this.$route.params
    },
    Lepay(){
   var x =   this.$store.getters.all_restful_LePay
      if(x){
        this.wechat();
        return x
      }
    }
  },
  methods:{
     wechat(){
       var xx = this.Lepay;
       alert('in wechat')
     if (xx) {
         alert(39999999)
         // alert(xx.body.Sign)
          function onBridgeReady(){
               console.info(typeof(xx)+' xx::::'+xx)
               // var that = this
             alert('OnBrideg ready')
             alert('watch aid', xx.body.appid)
             WeixinJSBridge.invoke(
                  'getBrandWCPayRequest', {
                       "appId":xx.body.appid,
                       "timeStamp":xx.body.timestamp,
                       "nonceStr":xx.body.noncestr,
                       "package":xx.body.pkg,
                       "signType":"MD5",
                       "paySign":xx.body.sign
                  },
                  function(res){
                       if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                           alert('here you go baby')
                       }else{
                           alert('there you go you!!! ')
                       }
                  }
             );
          }
          if (typeof WeixinJSBridge == "undefined"){
               if( document.addEventListener ){
                  document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
               }else if (document.attachEvent){
                   document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                   document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
               }
          }else{
               alert('esle go br ready')
               onBridgeReady();
          }

       // WeixinJSBridge.invoke(
       // 'getBrandWCPayRequest', {
       // });

     }
     // this.uname=GetQueryString("userName")
     }
  }


}

</script>
